/**
 * 
 */
package instant.mail;

import android.content.Context;
import android.media.MediaRecorder;

/**
 * @author qiangli
 * 
 */
public final class FileFormats {
	//mime type
	public static final String AUDIO_ANY = "audio/*";
	public static final String AUDIO_3GPP = "audio/3gpp";
	//public static final String AUDIO_AMR = "audio/amr";
	public static final String AUDIO_WAV = "audio/x-wav";
	// public static final String AUDIO_MPEG4 = "audio/mp4";

	//file extension
	public static final String EXT_3GPP = ".3gp";
	//public static final String EXT_AMR = ".amr";
	public static final String EXT_WAV = ".wav";
	// public static final String EXT_MPEG4 = ".mp4";

	public static final int BITRATE_5900 = 5900; // 3gp default
	public static final int BITRATE_64000 = 64000; // wav default

	public static final String EXT_JPG = ".jpg";

	//audio format
	// /** 3GPP media file format*/
	public static final int THREE_GPP = MediaRecorder.OutputFormat.THREE_GPP;
	// /** MPEG4 media file format*/
	// public static final int MPEG_4 = MediaRecorder.OutputFormat.MPEG_4;
	// /** Raw AMR file format */
	//public static final int RAW_AMR = MediaRecorder.OutputFormat.RAW_AMR;
	// ** Our extensions */
	// public static final int RAW_PCM = 1000 + MediaRecorder.OutputFormat.DEFAULT;
	public static final int RIFF_WAV = 1001 + MediaRecorder.OutputFormat.DEFAULT;

	//
	private FileFormats() {
	}

	public static final String extension(String mime) {
		if (AUDIO_3GPP.equals(mime)) {
			return EXT_3GPP;
		} else if (AUDIO_WAV.equals(mime)) {
			return EXT_WAV;
		}
		if (Constants.DEBUG_ENABLED) {
			throw new RuntimeException("Invalid mime type: "+ mime);
		} else {
			return EXT_3GPP;
		}
	}

	public static final boolean isRiffWave(String mime) {
		return (AUDIO_WAV.equals(mime));
	}
	
	public static final int format(String mime) {
		if (AUDIO_3GPP.equals(mime)) {
			return THREE_GPP;
		} else if (AUDIO_WAV.equals(mime)) {
			return RIFF_WAV;
		} 
		if (Constants.DEBUG_ENABLED) {
			throw new RuntimeException("Invalid mime type: "+ mime);
		} else {
			return THREE_GPP;
		}
	}
	
	public static final int indexOf(Context ctx, String mime) {
		final String[] fmts = ctx.getResources().getStringArray(R.array.compose_audio_format_values);
        for (int i = 0; i < fmts.length; i++) {
        	if (fmts[i].equals(mime)) {
        		return i;
        	}
        }
        return -1;
	}
}

// private static final String AUDIO_ANY = "audio/*";
// static final int BITRATE_AMR = 5900; // bits/sec
// static final int BITRATE_3GPP = 5900;

// public static final int DEFAULT = 0;
// /** 3GPP media file format*/
// public static final int THREE_GPP = 1;
// /** MPEG4 media file format*/
// public static final int MPEG_4 = 2;
// /** Raw AMR file format */
// public static final int RAW_AMR = 3;

// ---
// Filename extension .amr
// Internet media type audio/amr, audio/3gpp, audio/3gpp2
//
// Filename extension .m4a, .m4b, .m4p, .m4v, .m4r, .3gp, .mp4, .aac
// Internet media type audio/aac, audio/aacp, audio/3gpp, audio/3gpp2,
// audio/mp4, audio/MP4A-LATM, audio/mpeg4-generic
//
//
// Filename extension .3gp .3g2
// Internet media type video/3gpp, audio/3gpp, video/3gpp2, audio/3gpp2
// ---